<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象的小练习</title>
</head>

<body>
    <script>
        // 对象小结
        // 1.对象可以让代码结构更清晰
        // 2.对象是复杂数据类型 object
        // 3.本质：对象就是一组无序的相关属性和方法的集合
        // 4.构造函数泛指某一大类，比如苹果，不管是红色苹果还是绿色苹果，都统称为苹果
        // 5.对象实例特指一个事物，比如这个苹果，正在运行的电脑等
        // 6.for...in语句用于对对象的属性进行循环操作

        // 1.创建一个电脑对象，有颜色，重量，品牌，型号等属性，看电影、听音乐、玩游戏等方法
        function Computer(color, weight, trademark, model) {
            this.lx_color = color;
            this.lx_weight = weight;
            this.lx_trademark = trademark;
            this.lx_model = model;
            this.lx_seeMovie = function(movies) {
                console.log(movies);
            }
            this.lx_listenMusic = function(musics) {
                console.log(musics);
            }
            this.lx_playgame = function(games) {
                console.log(games);
            }
        }

        var lenovo = new Computer('silver', 100, 'lenovo', 'xiaoxinAir-2019');
        console.log(lenovo.lx_color);
        // 调用方法
        lenovo.lx_seeMovie('大鱼海棠');
        lenovo.lx_listenMusic('晴天');
        lenovo.lx_playgame('英雄联盟');




        // 简易计算器
        function Counter() {
            in_num = prompt("欢迎使用简易计算器：\n1.加法运算 \n2.减法运算 \n3.乘法运算 \n4.除法运算 \n5.退出：\n 请输入你的选项：")
            switch (in_num) {
                case '1':
                    add1 = parseFloat(prompt());
                    add2 = parseFloat(prompt());

                    let addition = function(add1, add2) {
                        let result = add1 + add2;
                        alert('结果为:' + result);
                    }
                    addition(add1, add2);
                    break;

                case '2':
                    sub1 = parseFloat(prompt());
                    sub2 = parseFloat(prompt());
                    let subtraction = function(sub1, sub2) {
                        let result = sub1 - sub2;
                        alert('结果为:' + result);
                    }
                    subtraction(sub1, sub2);
                    break;

                case '3':
                    mul1 = parseFloat(prompt());
                    mul2 = parseFloat(prompt());
                    let muliltplication = function(mul1, mul2) {
                        let result = mul1 * mul2;
                        alert('结果为:' + result);
                    }
                    muliltplication(mul1, mul2);
                    break;

                case '4':
                    div1 = parseFloat(prompt());
                    div2 = parseFloat(prompt());
                    let division = function(div1, div2) {
                        let result = div1 / div2;
                        alert('结果为:' + result);
                    }
                    division(div1, div2);
                    break;

                case '5':
                    break;
                default:
                    alert('请正确输入');
                    break;
            }
            // this.addition = function(add1, add2) {
            //     sum = add1 + add2;
            //     return sum;
            // }
            // this.subtraction = '2';
            // this.multiplication = '3';
            // this.division = '4';
        }
        var add = new Counter();
        console.log(typeof add);
        // console.log(add.addition(2, 3));
    </script>
</body>

</html>